package com.jp.vn.CustomAdapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.jp.vn.main.GreetingActivity;
import com.jp.vn.main.GreetingPractiseActivity;
import com.jp.vn.main.HiraganaActivity;
import com.jp.vn.main.KatakanaActivity;
import com.jp.vn.main.PhatAmActivity;
import com.jp.vn.main.R;
import com.jp.vn.main.SoDemActivity;
import com.jp.vn.main.ThoiGianActivity;
import com.jp.vn.main.TimKiemActivity;

public class ViewPagerAdapter extends PagerAdapter {

	Context context;
	public LayoutInflater inflater;
	ImageView btnHiragana, btnKatakana, btnTimKiem, btnPhatAm, btnGiaoTiep,
			btnThoiGian, btnSoDem, btnNguPhap, btnBo, btnChu, btnTuVung,
			btnLuyenTap;

	public ViewPagerAdapter(Context context) {
		this.context = context;
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return 2;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == ((View) arg1);
	}

	@Override
	public Object instantiateItem(View container, int position) {
		View layout = null;
		final Context mcontext = container.getContext();

		if (position == 0) {
			layout = inflater.inflate(R.layout.layout_menu1, null);

			btnHiragana = (ImageView) layout.findViewById(R.id.btnHiragana);
			btnKatakana = (ImageView) layout.findViewById(R.id.btnkatakana);
			btnPhatAm = (ImageView) layout.findViewById(R.id.btnPhatAm);
			btnTimKiem = (ImageView) layout.findViewById(R.id.btnTimKiem);
			btnGiaoTiep = (ImageView) layout.findViewById(R.id.btnGiaoTiep);
			btnSoDem = (ImageView) layout.findViewById(R.id.btnSoDem);

			btnHiragana.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent hiragana = new Intent(mcontext,
							HiraganaActivity.class);
					mcontext.startActivity(hiragana);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});

			btnKatakana.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {

					Intent katakana = new Intent(mcontext,
							KatakanaActivity.class);
					mcontext.startActivity(katakana);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});

			btnGiaoTiep.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent greeting = new Intent(mcontext,
							GreetingActivity.class);
					mcontext.startActivity(greeting);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});

			btnPhatAm.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					Intent PhatAm = new Intent(mcontext, PhatAmActivity.class);
					mcontext.startActivity(PhatAm);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});

			btnTimKiem.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {
					Intent TimKiem = new Intent(mcontext, TimKiemActivity.class);
					mcontext.startActivity(TimKiem);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});

			btnSoDem.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Intent SoDem = new Intent(mcontext, SoDemActivity.class);
					mcontext.startActivity(SoDem);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});

			((ViewPager) container).addView(layout);
		}

		else {

			layout = inflater.inflate(R.layout.layout_menu2, null);

			btnBo = (ImageView) layout.findViewById(R.id.btnBoCoBan);
			btnChu = (ImageView) layout.findViewById(R.id.btnChuCoBan);
			btnTuVung = (ImageView) layout.findViewById(R.id.btnTuVung);
			btnThoiGian = (ImageView) layout.findViewById(R.id.btnThoiGian);
			btnNguPhap = (ImageView) layout.findViewById(R.id.btnNguPhap);
			btnLuyenTap = (ImageView) layout.findViewById(R.id.btnLuyenTap);

			btnThoiGian.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {

					Intent time = new Intent(mcontext, ThoiGianActivity.class);
					mcontext.startActivity(time);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});
			
			btnTuVung.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View arg0) {

					Intent vocabulary = new Intent(mcontext, GreetingPractiseActivity.class);
					mcontext.startActivity(vocabulary);
					((Activity) mcontext).overridePendingTransition(
							R.anim.right_in, R.anim.left_out);
				}
			});


			((ViewPager) container).addView(layout);
		}

		return layout;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		View view = (View) object;
		((ViewPager) container).removeView(view);
	}

}
